<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js异步编程之宏微任务进度条</title>
  <style>
    .loading {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 0;
      height: 40px;
      background-color: #9b59b6;
      color: #fff;
    }
  </style>
</head>
<body>
  <div class="loading"></div>
  <script>
    (function () {
      let i = 0
      const loading = document.querySelector('.loading');
      (function run() {
        loading.style.width = `${i}%`
        loading.innerHTML = `${i}%`
        if (++i <= 100) {
          setTimeout(run, 50)
        }
      })()
    })()
  </script>
</body>
</html>